home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 September (Japanese) / CICA Shareware for Windows CD-ROM (Walnut Creek) (September 1995) (Japanese) (Disc 2).iso / disc2 / nt / ntperf.exe / PERFTOOLS / SRC / PERFMON / LINE.C_ / LINE.C
Encoding:
C/C++ Source or Header  |  1993-05-15  |  27.3 KB  |  1,042 lines

  1.  
  2.  
  3. //==========================================================================//
  4. //                                  Includes                                //
  5. //==========================================================================//
  6.  
  7.  
  8. #include "perfmon.h"    // included by all source files
  9. #include "line.h"       // external declarations for this file
  10. //#include <tchar.h>      // for _tcsncpy
  11.  
  12. #include "fileutil.h"   // for FileRead, FileWrite
  13. #include "pmemory.h"     // for MemoryXXX (mallloc-type) routines
  14. #include "perfdata.h"   // for UpdateSystemData, et al
  15. #include "perfmops.h"   // for InsertLine
  16. #include "system.h"     // for SystemAdd
  17. #include "utils.h"
  18. #include "playback.h"   // for PlayingBackLog
  19. #include "counters.h"   // CounterEntry
  20.  
  21. #include <string.h>     // for strncpy
  22. #ifdef UNICODE
  23. #define _tcsncpy    wcsncpy
  24. #else
  25. #define _tcsncpy    strncpy
  26. #endif
  27.  
  28. TCHAR LOCAL_SYS_CODE_NAME[] = TEXT("....") ;
  29. #define  sizeofCodeName sizeof(LOCAL_SYS_CODE_NAME) / sizeof(TCHAR) - 1
  30.  
  31. // Local Function prototype
  32. PLINE ReadLine (PPERFSYSTEM *ppSystem,
  33.                 PPPERFSYSTEM ppSystemFirst,
  34.                 PPERFDATA *ppPerfData, 
  35.                 HANDLE hFile,
  36.                 int LineType,
  37.                 PDISKLINE  *ppDiskLine,
  38.                 DWORD *pSizeofDiskLine) ;
  39.  
  40.  
  41.  
  42. //==========================================================================//
  43. //                             Exported Functions                           //
  44. //==========================================================================//
  45.  
  46.  
  47. PLINE LineAllocate (void)
  48. /*
  49.    Effect:        Allocate and initialize a Line data structure. Lines
  50.                   are used as the primary elements of both charts and
  51.                   alerts.
  52.  
  53.                   Establish any representation invariants for the Line
  54.                   type.
  55.  
  56.                   Also alllocate another structure, an array of data
  57.                   elements, iNumDataValues long.
  58. */
  59.    {  // LineAllocate
  60.    PLINE          pLine ;
  61.  
  62.    pLine = MemoryAllocate (sizeof (LINESTRUCT)) ;
  63.  
  64.    if (pLine)
  65.       {
  66. //  don't need to zero these again since MemoryAllocate is using
  67. //  GMEM_ZEROPOINT
  68. //      pLine->pLineNext = NULL ;
  69. //      pLine->pLineCounterNext = NULL ;
  70.  
  71.       // do want to do this since (FLOAT)0.0 is not 0
  72.       pLine->lnMinValue =
  73.       pLine->lnMaxValue =
  74.       pLine->lnAveValue = (FLOAT) 0.0 ;
  75.  
  76.       if (PlayingBackLog())
  77.          {
  78.          pLine->bFirstTime = FALSE ;
  79.          }
  80.       else
  81.          {
  82. //         pLine->bFirstTime = TRUE ;
  83.          // we want to take 2 samples before plotting the first data
  84.          pLine->bFirstTime = 2 ;
  85.          }
  86.       }  // if
  87.  
  88.    return (pLine) ;
  89.    }  // LineAllocate
  90.  
  91.  
  92. void LineFree (PLINE pLine)
  93.    {  // LineFree
  94.    // free any memory allocated by this line
  95.    if (pLine->lnSystemName)
  96.       MemoryFree (pLine->lnSystemName) ;
  97.  
  98.    if (pLine->lnObjectName)
  99.       MemoryFree (pLine->lnObjectName) ;
  100.  
  101.    if (pLine->lnCounterName)
  102.       MemoryFree (pLine->lnCounterName) ;
  103.  
  104.    if (pLine->lnInstanceName)
  105.       MemoryFree (pLine->lnInstanceName) ;
  106.  
  107.    if (pLine->lnParentObjName)
  108.       MemoryFree (pLine->lnParentObjName) ;
  109.  
  110.    if (pLine->lnPINName)
  111.       MemoryFree (pLine->lnPINName) ;
  112.  
  113.    if (pLine->lpszAlertProgram)
  114.       MemoryFree (pLine->lpszAlertProgram) ;
  115.  
  116.    if (pLine->hPen)
  117.       DeletePen(pLine->hPen);
  118.  
  119.    if (pLine->hBrush)
  120.       DeletePen(pLine->hBrush);
  121.  
  122.    if (pLine->lnValues)
  123.       MemoryFree (pLine->lnValues) ;
  124.  
  125.    if (pLine->aiLogIndexes)
  126.       MemoryFree (pLine->aiLogIndexes) ;
  127.  
  128.    MemoryFree (pLine) ;
  129.    }  // LineFree
  130.  
  131.  
  132.  
  133. void LineAppend (PPLINE ppLineFirst, 
  134.                  PLINE pLineNew)
  135.    {
  136.    PLINE          pLine ;
  137.  
  138.    if (!*ppLineFirst)
  139.       *ppLineFirst = pLineNew ;
  140.    else  
  141.       {  // else
  142.       for (pLine = *ppLineFirst ;
  143.            pLine->pLineNext ;
  144.            pLine = pLine->pLineNext)
  145.          /* nothing */ ;
  146.       pLine->pLineNext = pLineNew ;
  147.       }  // else
  148.    }
  149.  
  150.  
  151.  
  152. BOOL LineRemove (PPLINE ppLineFirst,
  153.                  PLINE pLineRemove)
  154.    {
  155.    PLINE          pLine ;
  156.  
  157.    if (*ppLineFirst == pLineRemove)
  158.       {
  159.       *ppLineFirst = (*ppLineFirst)->pLineNext ;
  160.       return (TRUE) ;
  161.       }
  162.  
  163.    for (pLine = *ppLineFirst ;
  164.         pLine->pLineNext ;
  165.         pLine = pLine->pLineNext)
  166.       {   // for
  167.       if (pLine->pLineNext == pLineRemove)
  168.          {
  169.          pLine->pLineNext = pLineRemove->pLineNext ;
  170.          return (TRUE) ;
  171.          }  // if
  172.       }  // for
  173.  
  174.    return (FALSE) ;
  175.    }  // LineRemove
  176.  
  177.  
  178.  
  179. int NumLines (PLINE pLineFirst)
  180.    {  // NumLines
  181.    PLINE          pLine ;
  182.    int            iNumLines ;
  183.  
  184.    if (!pLineFirst)
  185.       return (0) ;
  186.  
  187.   
  188.    iNumLines = 0 ;
  189.    for (pLine = pLineFirst ;
  190.         pLine ;
  191.         pLine = pLine->pLineNext)
  192.       {  // for
  193.       iNumLines++ ;
  194.       }  // for
  195.  
  196.  
  197.    return (iNumLines) ;
  198.    }  // NumLines
  199.  
  200.  
  201.  
  202. LPTSTR LineInstanceName (PLINE pLine)
  203.    {
  204.    if (pLine->lnObject.NumInstances <= 0)
  205.       return (NULL) ;
  206.    else
  207.       return (pLine->lnInstanceName) ;
  208.    }
  209.  
  210.  
  211. LPTSTR LineParentName (PLINE pLine)
  212.    {
  213.    if (pLine->lnObject.NumInstances <= 0)
  214.       return (NULL) ;
  215.    else if (pLine->lnInstanceDef.ParentObjectTitleIndex)
  216.       return (pLine->lnPINName) ;
  217.    else
  218.       return (NULL) ;
  219.    }
  220.  
  221.  
  222.  
  223. void LineCounterAppend (PPLINE ppLineFirst, 
  224.                         PLINE pLineNew)
  225.    {
  226.    PLINE          pLine ;
  227.  
  228.    if (!*ppLineFirst)
  229.       *ppLineFirst = pLineNew ;
  230.    else  
  231.       {  // else
  232.       for (pLine = *ppLineFirst ;
  233.            pLine->pLineCounterNext ;
  234.            pLine = pLine->pLineCounterNext)
  235.          /* nothing */ ;
  236.       pLine->pLineCounterNext = pLineNew ;
  237.       }  // else
  238.    }
  239.  
  240.  
  241.  
  242. BOOL EquivalentLine (PLINE pLine1,
  243.                      PLINE pLine2)
  244.    {  // LineEquivalent
  245.    return (pstrsame (pLine1->lnCounterName, pLine2->lnCounterName) &&
  246.            pstrsame (pLine1->lnInstanceName, pLine2->lnInstanceName) &&
  247.            pstrsame (pLine1->lnPINName, pLine2->lnPINName) &&
  248.            pstrsame (pLine1->lnObjectName, pLine2->lnObjectName) &&
  249.            pstrsamei (pLine1->lnSystemName, pLine2->lnSystemName)) ;
  250.    }  // LineEquivalent
  251.  
  252.  
  253. PLINE FindEquivalentLine (PLINE pLineToFind,
  254.                           PLINE pLineFirst)
  255.    {
  256.    PLINE          pLine ;
  257.  
  258.    for (pLine = pLineFirst ;
  259.         pLine ;
  260.         pLine = pLine->pLineNext)
  261.       {  // for
  262.       if (EquivalentLine (pLine, pLineToFind))
  263.          return (pLine) ;
  264.       }  // for
  265.  
  266.    return (NULL) ;
  267.    }  // FindEquivalentLine
  268.  
  269. // This routine is used only to read the system name from a disk string
  270. // It is mainly for performance improvement.
  271. LPTSTR DiskStringReadSys (PDISKSTRING pDS)
  272.    {  // DiskStringReadSys
  273.    LPTSTR         lpszText ;
  274.    LPTSTR         pDiskSysName ;
  275.    int            iIndex ;
  276.    BOOL           bLocalSysName = FALSE ;
  277.  
  278.    if (pDS->dwLength == 0)
  279.       {
  280.       return (NULL) ;
  281.       }
  282.  
  283.    if (pDS->dwLength == sizeofCodeName)
  284.       {
  285.       // check for LOCAL_SYS_CODE_NAME
  286.       bLocalSysName = TRUE ;
  287.       pDiskSysName = (LPTSTR)((PBYTE) pDS + pDS->dwOffset) ;
  288.       for (iIndex = 0 ; iIndex < sizeofCodeName; iIndex++, pDiskSysName++)
  289.          {
  290.          if (*pDiskSysName != LOCAL_SYS_CODE_NAME[iIndex])
  291.             {
  292.             bLocalSysName = FALSE ;
  293.             break ;
  294.             }
  295.          }
  296.       }
  297.  
  298.    if (bLocalSysName)
  299.       {
  300.       lpszText =
  301.          MemoryAllocate ((lstrlen(LocalComputerName)+1) * sizeof(TCHAR)) ;
  302.       if (lpszText)
  303.          {
  304.          lstrcpy (lpszText, LocalComputerName) ;
  305.          }
  306.       }
  307.    else
  308.       {
  309.       lpszText = MemoryAllocate (sizeof (TCHAR) * (pDS->dwLength + 1)) ;
  310.       if (lpszText)
  311.          {
  312.          _tcsncpy ((WCHAR *)lpszText, (WCHAR *)((PBYTE) pDS + pDS->dwOffset),
  313.                   pDS->dwLength) ;
  314.          }
  315.       }
  316.  
  317.    return (lpszText) ;
  318.    }  // DiskStringReadSys
  319.  
  320.  
  321.  
  322. LPTSTR DiskStringRead (PDISKSTRING pDS)
  323.    {  // DiskStringRead
  324.    LPTSTR         lpszText ;
  325.  
  326.    if (pDS->dwLength == 0)
  327.       {
  328.       return (NULL) ;
  329.       }
  330.  
  331.    lpszText = MemoryAllocate (sizeof (TCHAR) * (pDS->dwLength + 1)) ;
  332.    if (!lpszText)
  333.       {
  334.       return (NULL) ;
  335.       }
  336.  
  337.    _tcsncpy ((WCHAR *)lpszText, (WCHAR *)((PBYTE) pDS + pDS->dwOffset),
  338.             pDS->dwLength) ;
  339.  
  340.    return (lpszText) ;
  341.    }  // DiskStringRead
  342.  
  343.  
  344. int DiskStringLength (LPTSTR lpszText)
  345.    {
  346.    if (!lpszText)
  347.       return (0) ;
  348.    else
  349.       return (lstrlen (lpszText)) ;
  350.    }
  351.  
  352. PBYTE DiskStringCopy (PDISKSTRING pDS, LPTSTR lpszText, PBYTE pNextFree)
  353.    {
  354.    if (!lpszText)
  355.       {
  356.       pDS->dwOffset = 0 ;
  357.       pDS->dwLength = 0 ;
  358.       return (pNextFree) ;
  359.       }
  360.    else
  361.       {
  362.       pDS->dwOffset = pNextFree - (PBYTE) pDS ;
  363.       pDS->dwLength = DiskStringLength (lpszText) ;
  364.       _tcsncpy ((WCHAR *)pNextFree, (WCHAR *)lpszText, pDS->dwLength) ;
  365.       return (pNextFree + pDS->dwLength * sizeof(TCHAR)) ;
  366.       }
  367.    }  // DiskStringCopy
  368.    
  369.  
  370. void CounterName (PPERFSYSTEM pSystem, 
  371.                   PPERFCOUNTERDEF pCounter, 
  372.                   LPTSTR lpszCounter)
  373.    {  // CounterName
  374. //!!   strclr (lpszCounter) ;
  375.    lpszCounter [0] = TEXT('\0') ;
  376.    QueryPerformanceName (pSystem, 
  377.                          pCounter->CounterNameTitleIndex, 
  378.                          0, 256,
  379.                          lpszCounter,
  380.                          FALSE) ;
  381.    }  // CounterName
  382.  
  383.  
  384.  
  385. PPERFOBJECT LineFindObject (PPERFSYSTEM pSystem,
  386.                             PPERFDATA pPerfData,
  387.                             PLINE pLine)
  388. /*
  389.    Effect:        Set the lnObject field of pLine to the object with the
  390.                   name of lnObjectName, and return TRUE. Return FALSE if
  391.                   there is no such object.
  392. */
  393.    {  // LineFindObject
  394.    PPERFOBJECT    pObject ;
  395.  
  396.    pObject = GetObjectDefByName (pSystem, pPerfData, pLine->lnObjectName) ;
  397.    
  398.    if (pObject)
  399.       {
  400.       pLine->lnObject = *pObject ;
  401.       return (pObject) ;
  402.       }
  403.    else
  404.       return (NULL) ;
  405.    }  // LineFindObject
  406.    
  407.  
  408.  
  409. PPERFCOUNTERDEF LineFindCounter (PPERFSYSTEM pSystem,
  410.                                  PPERFOBJECT pObject,
  411.                                  PPERFDATA pPerfData,
  412.                                  PLINE pLine)
  413.    {  // LineFindCounter
  414.    UINT               i ;
  415.    PPERFCOUNTERDEF   pCounter ;
  416.    TCHAR             szCounter [256] ;
  417.  
  418.    for (i = 0, pCounter = FirstCounter (pObject) ;
  419.         i < pObject->NumCounters ;
  420.         i++, pCounter = NextCounter (pCounter))
  421.       {  // for
  422.       CounterName (pSystem, pCounter, szCounter) ;
  423.       if (strsame (szCounter, pLine->lnCounterName))
  424.          {
  425.          pLine->lnCounterDef = *pCounter ;
  426.          return (pCounter) ;
  427.          }  // if
  428.       }  // for
  429.  
  430.    return (NULL) ;
  431.    }  // LineFindCounter
  432.  
  433.                       
  434. PPERFINSTANCEDEF LineFindInstance (PPERFDATA pPerfData,
  435.                                    PPERFOBJECT pObject,
  436.                                    PLINE pLine)
  437.    {  // LineFindInstance
  438.   
  439.                                    
  440.    PPERFINSTANCEDEF  pInstance = NULL ;
  441.  
  442.    if ((pObject->NumInstances > 0) && pLine->lnInstanceName)
  443.       {
  444.       // instances exist, find the right one
  445.       
  446.       if (pLine->lnUniqueID != PERF_NO_UNIQUE_ID)
  447.          {
  448.          pInstance = GetInstanceByUniqueID(pObject, pLine->lnUniqueID) ;
  449.          }
  450.       else
  451.          {
  452.          pInstance = GetInstanceByName(pPerfData, pObject,
  453.                         pLine->lnInstanceName, pLine->lnPINName) ;
  454.          }
  455.       }
  456.  
  457.    if (pInstance)
  458.       {
  459.       pLine->lnInstanceDef = *pInstance ;
  460.       }
  461.  
  462.    return (pInstance) ;
  463.    }  // LineFindInstance
  464.  
  465.  
  466.  
  467.  
  468. void ReadLines (HANDLE hFile,
  469.                 DWORD dwNumLines,
  470.                 PPPERFSYSTEM ppSystemFirst,
  471.                 PPLINE ppLineFirst,
  472.                 int LineType)
  473.    {
  474.    DWORD          i ;
  475.    PPERFDATA      pPerfData ;
  476.    PLINE          pLine ;
  477.    PPERFSYSTEM    pSystem ;
  478.    PDISKLINE      pDiskLine = NULL ;
  479.    DWORD          SizeofDiskLine = 0 ;  // bytes in pDiskLine
  480.  
  481.  
  482.    pPerfData = AllocatePerfData () ;
  483.    pSystem = *ppSystemFirst ;
  484.  
  485. #if 0
  486.    if (!pSystem)
  487.       {
  488.       pSystem = SystemAdd (ppSystemFirst, LocalComputerName) ;
  489.       pSystem = *ppSystemFirst ; //!!
  490.       }
  491.  
  492.    UpdateSystemData (pSystem, &pPerfData) ;
  493. #endif
  494.    pDiskLine = MemoryAllocate (FilePathLen) ;
  495.    if (!pDiskLine)
  496.       {
  497.       // no memory to begin with, forget it
  498.       DlgErrorBox (hWndMain, ERR_NO_MEMORY) ;
  499.       return ;
  500.       }
  501.    SizeofDiskLine = FilePathLen ;
  502.  
  503.    for (i = 0 ;
  504.         i < dwNumLines ;
  505.         i++)
  506.       {
  507.       pLine = ReadLine (&pSystem, ppSystemFirst, &pPerfData, hFile,
  508.             LineType, &pDiskLine, &SizeofDiskLine) ;
  509.       if (pLine)
  510.          InsertLine (pLine)  ;
  511.       }
  512.    
  513.    if (pDiskLine)
  514.       {
  515.       MemoryFree (pDiskLine);
  516.       }
  517.  
  518.    BuildValueListForSystems (*ppSystemFirst, *ppLineFirst) ;
  519.  
  520.    MemoryFree (pPerfData) ;
  521.    }  // ReadLines
  522.  
  523.  
  524.  
  525. void LineSetCounter (PLINE pLine,
  526.                      PPERFSYSTEM pSystem,
  527.                      PPERFCOUNTERDEF pCounter,
  528.                      PPERFINSTANCEDEF pInstance)
  529. /*
  530.    Effect:        Set the counter-specific portions of pLine to point to
  531.                   the desired counter.
  532.  
  533.    Called By:     AddLine, ReadLine.
  534. */
  535.    {
  536.    }
  537.  
  538.  
  539. PLINE ReadLine (PPERFSYSTEM *ppSystem,
  540.                 PPPERFSYSTEM ppSystemFirst,
  541.                 PPERFDATA *ppPerfData,
  542.                 HANDLE hFile,
  543.                 int LineType,
  544.                 PDISKLINE  *ppDiskLine,
  545.                 DWORD *pSizeofDiskLine)
  546.  
  547.  
  548. /*
  549.    Effect:        Read in a line from the file hFile, at the current file
  550.                   position.
  551.  
  552.    Internals:     The very first characters are a line signature, then a 
  553.                   length integer. If the signature is correct, then allocate
  554.                   the length amount, and work with that.
  555. */
  556.    {  // ReadLine
  557.    PLINE             pLine ;
  558.  
  559.    struct
  560.       {
  561.       DWORD             dwSignature ;
  562.       DWORD             dwLength ;
  563.       } LineHeader ;
  564.  
  565.    PPERFOBJECT       pObject ;
  566.    PPERFCOUNTERDEF   pCounter ;
  567.    PDISKLINE         pDiskLine ;    // Local copy of the pointer
  568.  
  569. #ifdef   KEEP_IT
  570.    int               i ;
  571.    int               iCounterIndex ;
  572.    int               j ;
  573.    PERF_COUNTER_BLOCK *pCounterBlock ;
  574. #endif
  575.  
  576.    PPERFINSTANCEDEF  pInstance ;
  577. //   PPERFINSTANCEDEF  pInstanceParent ;
  578. //   TCHAR          szInstanceParent [256] ;
  579. //   TCHAR          szObjectParent [PerfObjectLen] ;
  580.  
  581.    pLine = NULL ;
  582.  
  583.  
  584.    //=============================//
  585.    // read and compare signature  //
  586.    //=============================//
  587.  
  588.    if (!FileRead (hFile, &LineHeader, sizeof (LineHeader)))
  589.       return (NULL) ;
  590.  
  591.  
  592.    if (LineHeader.dwSignature != dwLineSignature ||
  593.        LineHeader.dwLength == 0)
  594.       {
  595.       SetLastError (ERROR_BAD_FORMAT) ;
  596.       return (NULL) ;
  597.       }
  598.  
  599.  
  600.    //=============================//
  601.    // read and allocate length    //
  602.    //=============================//
  603.  
  604.  
  605. //   if (!FileRead (hFile, &dwLength, sizeof (dwLength)) || dwLength == 0)
  606. //      return (NULL) ;
  607.  
  608.  
  609.    // check if we need a bigger buffer, 
  610.    // normally, it should be the same except the first time...
  611.    if (LineHeader.dwLength > *pSizeofDiskLine)
  612.       {
  613.       if (*ppDiskLine)
  614.          {
  615.          // free the previous buffer
  616.          MemoryFree (*ppDiskLine);
  617.          *pSizeofDiskLine = 0 ;
  618.          }
  619.  
  620.       // re-allocate a new buffer
  621.       *ppDiskLine = (PDISKLINE) MemoryAllocate (LineHeader.dwLength) ;
  622.       if (!(*ppDiskLine))
  623.          {
  624.          // no memory, should flag an error...
  625.          return (NULL) ;
  626.          }
  627.       *pSizeofDiskLine = LineHeader.dwLength ;
  628.       }
  629.       
  630.    pDiskLine = *ppDiskLine ;
  631.  
  632.  
  633.    //=============================//
  634.    // copy diskline, alloc line   //
  635.    //=============================//
  636.  
  637.    if (!FileRead (hFile, pDiskLine, LineHeader.dwLength))
  638.       return (NULL) ;
  639.  
  640.  
  641.    pLine = LineAllocate () ;
  642.    if (!pLine)
  643.       {
  644.       return (NULL) ;
  645.       }
  646.  
  647.    pLine->iLineType = pDiskLine->iLineType ;
  648.  
  649.  
  650.    //=============================//
  651.    // convert system information  //
  652.    //=============================//
  653.  
  654.    pLine->lnSystemName = DiskStringReadSys (&(pDiskLine->dsSystemName)) ;
  655.    if (!pLine->lnSystemName)
  656.       goto ErrorBadLine ;
  657.  
  658.    if (!*ppSystem || !strsamei (pLine->lnSystemName, (*ppSystem)->sysName))
  659.       {
  660.       *ppSystem = SystemAdd (ppSystemFirst, pLine->lnSystemName) ;
  661.       if (!*ppSystem)
  662.          {
  663.          SetLastError (ERROR_BAD_FORMAT) ;
  664.          goto ErrorBadLine ;
  665.          }
  666.  
  667.       UpdateSystemData (*ppSystem, ppPerfData) ;
  668.       }  // if
  669.  
  670.    //=============================//
  671.    // convert object information  //
  672.    //=============================//
  673.  
  674.    pLine->lnObjectName = DiskStringRead (&(pDiskLine->dsObjectName)) ;
  675.    if (!pLine->lnObjectName)
  676.       goto ErrorBadLine ;
  677.  
  678.    pObject = LineFindObject (*ppSystem, *ppPerfData, pLine) ;
  679.    if (!pObject)
  680.       {
  681.       SetLastError (ERROR_BAD_FORMAT) ;
  682.       goto ErrorBadLine ;
  683.       }
  684.  
  685.    //=============================//
  686.    // convert counter information //
  687.    //=============================//
  688.  
  689.    pLine->lnCounterName = DiskStringRead (&(pDiskLine->dsCounterName)) ;
  690.    if (!pLine->lnCounterName)
  691.       goto ErrorBadLine ;
  692.  
  693.    pCounter = LineFindCounter (*ppSystem, pObject, *ppPerfData, pLine) ;
  694.    if (!pCounter)
  695.       {
  696.       SetLastError (ERROR_BAD_FORMAT) ;
  697.       goto ErrorBadLine ;
  698.       }
  699.  
  700.    //=============================//
  701.    // convert instance info       //
  702.    //=============================//
  703.  
  704.    pLine->lnUniqueID = pDiskLine->dwUniqueID ;
  705.    pLine->lnInstanceName = DiskStringRead (&(pDiskLine->dsInstanceName)) ;
  706.    pLine->lnPINName = DiskStringRead (&(pDiskLine->dsPINName)) ;
  707.  
  708.    pInstance = LineFindInstance (*ppPerfData, pObject, pLine) ;
  709.  
  710.    if (pInstance)
  711.       {
  712.       pLine->lnParentObjName = DiskStringRead (&(pDiskLine->dsParentObjName)) ;
  713.       }
  714.  
  715.  
  716.    //=============================//
  717.    // convert chart information   //
  718.    //=============================//
  719.  
  720.    if (LineType == IDM_VIEWCHART)
  721.       {
  722.       pLine->Visual = pDiskLine->Visual ;
  723.       pLine->hPen = CreatePen (pLine->Visual.iStyle,
  724.                                pLine->Visual.iWidth, 
  725.                                pLine->Visual.crColor) ;
  726.       pLine->iScaleIndex = pDiskLine->iScaleIndex ;
  727.       pLine->eScale = pDiskLine->eScale ;
  728.       }
  729.  
  730.  
  731.    //=============================//
  732.    // convert alert information   //
  733.    //=============================//
  734.  
  735.    if (LineType == IDM_VIEWALERT)
  736.       {
  737.       pLine->Visual = pDiskLine->Visual ;
  738.       pLine->hBrush = CreateSolidBrush (pLine->Visual.crColor) ;
  739.       pLine->bAlertOver = pDiskLine->bAlertOver ;
  740.       pLine->eAlertValue = pDiskLine->eAlertValue ;
  741.       pLine->lpszAlertProgram = DiskStringRead (&(pDiskLine->dsAlertProgram)) ;
  742.       pLine->bEveryTime = pDiskLine->bEveryTime ;
  743.       pLine->bAlerted = FALSE ;
  744.       }
  745.  
  746.  
  747.    //=============================//
  748.    // Convert the nasty stuff     //
  749.    //=============================//
  750.  
  751.  
  752.    pLine->lnCounterType = pCounter->CounterType;
  753.    pLine->lnCounterLength = pCounter->CounterSize;
  754.  
  755.  
  756.    // we don't need these line info since we will get it
  757.    // from the first couple clock ticks...
  758.    // If we decide to keep these line, just define KEEP_IT
  759. #ifdef   KEEP_IT
  760.    pLine->lnOldTime = (*ppPerfData)->PerfTime ;
  761.    pLine->lnNewTime = (*ppPerfData)->PerfTime ;
  762.    pLine->lnOldTime100Ns = (*ppPerfData)->PerfTime100nSec ;
  763.    pLine->lnNewTime100Ns = (*ppPerfData)->PerfTime100nSec;
  764.  
  765.    pLine->lnPerfFreq = (*ppPerfData)->PerfFreq ;
  766.  
  767.    for (j = 0 ; j < 2 ; j++)
  768.       {
  769.       pLine->lnaCounterValue[j].LowPart = 0 ;
  770.       pLine->lnaCounterValue[j].HighPart = 0 ;
  771.       }
  772.  
  773.  
  774.    if (pObject->NumInstances > 0 && pInstance)
  775.       {
  776.       pCounterBlock = (PERF_COUNTER_BLOCK *) ( (PBYTE) pInstance +
  777.                        pInstance->ByteLength);
  778.       }
  779.    else
  780.       {
  781.       pCounterBlock = (PERF_COUNTER_BLOCK *) ( (PBYTE) pObject +
  782.                        pObject->DefinitionLength);
  783.       }
  784.  
  785.    if (pLine->lnCounterLength <= 4)
  786.        pLine->lnaOldCounterValue[0].LowPart =
  787.                * ( (DWORD FAR *) ( (PBYTE)pCounterBlock +
  788.                pCounter[0].CounterOffset));
  789.    else
  790.       {
  791.       pLine->lnaOldCounterValue[0] =
  792.               * ( (LARGE_INTEGER *) ( (PBYTE)pCounterBlock +
  793.               pCounter[0].CounterOffset));
  794.       }
  795.  
  796.    // Get second counter, only if we are not at
  797.    // the end of the counters; some computations
  798.    // require a second counter
  799.  
  800.    iCounterIndex = CounterIndex (pCounter, pObject) ;
  801.    if ((UINT) iCounterIndex < pObject->NumCounters - 1 &&
  802.        iCounterIndex != -1)
  803.       {
  804.       if (pLine->lnCounterLength <= 4)
  805.           pLine->lnaOldCounterValue[1].LowPart =
  806.                   * ( (DWORD FAR *) ( (PBYTE)pCounterBlock +
  807.                   pCounter[1].CounterOffset));
  808.       else
  809.          pLine->lnaOldCounterValue[1] =
  810.                  * ( (LARGE_INTEGER *) ( (PBYTE)pCounterBlock +
  811.                  pCounter[1].CounterOffset));
  812.       }
  813.  
  814. //   pLine->valNext = CounterFuncEntry ;
  815.    pLine->valNext = CounterEntry ;
  816.  
  817.    pLine->lnaOldCounterValue[0] = pLine->lnaCounterValue[0];
  818.    pLine->lnaOldCounterValue[1] = pLine->lnaCounterValue[1];
  819. #endif   // KEEP_IT
  820.  
  821.  
  822. //   pLine->valNext = CounterFuncEntry ;
  823.    pLine->valNext = CounterEntry ;
  824.  
  825.    return (pLine) ;
  826.  
  827.  
  828. ErrorBadLine:
  829.    if (!pLine)
  830.       {
  831.       LineFree (pLine) ;
  832.       }
  833.    return (NULL) ;
  834.    }  // ReadLine
  835.  
  836.  
  837.  
  838.  
  839. BOOL WriteLine (PLINE pLine,
  840.                 HANDLE hFile)
  841.    {  // WriteLine
  842.    PDISKLINE      pDiskLine ;
  843.    DWORD          dwSignature ;
  844.    DWORD          dwLength ;
  845.    PBYTE          pNextFree ;
  846.    BOOL           bConvertName ;
  847.  
  848.    //=============================//
  849.    // write signature             //
  850.    //=============================//
  851.  
  852.    dwSignature = dwLineSignature ;
  853.    if (!FileWrite (hFile, &dwSignature, sizeof (dwSignature)))
  854.       return (FALSE) ;
  855.  
  856.    if (IsLocalComputer(pLine->lnSystemName))
  857.       {
  858.       bConvertName = TRUE ;
  859.       }
  860.    else
  861.       {
  862.       bConvertName = FALSE ;
  863.       }
  864.  
  865.    //=============================//
  866.    // compute and allocate length //
  867.    //=============================//
  868.  
  869.  
  870.    dwLength = sizeof (DISKLINE) ;
  871.    if (bConvertName)
  872.       {
  873.       dwLength += DiskStringLength (LOCAL_SYS_CODE_NAME) * sizeof (TCHAR) ;
  874.       }
  875.    else
  876.       {
  877.       dwLength += DiskStringLength (pLine->lnSystemName) * sizeof (TCHAR) ;
  878.       }
  879.    dwLength += DiskStringLength (pLine->lnObjectName) * sizeof (TCHAR) ;
  880.    dwLength += DiskStringLength (pLine->lnCounterName) * sizeof (TCHAR) ;
  881.    dwLength += DiskStringLength (pLine->lnInstanceName) * sizeof (TCHAR) ;
  882.    dwLength += DiskStringLength (pLine->lnPINName) * sizeof (TCHAR) ;
  883.    dwLength += DiskStringLength (pLine->lnParentObjName) * sizeof (TCHAR) ;
  884.    dwLength += DiskStringLength (pLine->lpszAlertProgram) * sizeof (TCHAR) ;
  885.  
  886.  
  887.    if (!FileWrite (hFile, &dwLength, sizeof (dwLength)))
  888.       return (FALSE) ;
  889.  
  890.    pDiskLine = (PDISKLINE) MemoryAllocate (dwLength) ;
  891.    if (!pDiskLine)
  892.       return (FALSE) ;
  893.  
  894.    pNextFree = (PBYTE) pDiskLine + sizeof (DISKLINE) ;
  895.  
  896.  
  897.    //=============================//
  898.    // convert fixed size fields   //
  899.    //=============================//
  900.  
  901.    pDiskLine->iLineType = pLine->iLineType ;
  902.    pDiskLine->dwUniqueID = pLine->lnUniqueID ;
  903.    pDiskLine->Visual = pLine->Visual ;
  904.    pDiskLine->iScaleIndex = pLine->iScaleIndex ;
  905.    pDiskLine->eScale = pLine->eScale ;
  906.    pDiskLine->bAlertOver = pLine->bAlertOver ;
  907.    pDiskLine->eAlertValue = pLine->eAlertValue ;
  908.    pDiskLine->bEveryTime = pLine->bEveryTime ;
  909.  
  910.  
  911.    //=============================//
  912.    // copy disk string fields     //
  913.    //=============================//
  914.  
  915.    if (bConvertName)
  916.       {
  917.       pNextFree = DiskStringCopy (&pDiskLine->dsSystemName, 
  918.                                   LOCAL_SYS_CODE_NAME,
  919.                                   pNextFree) ;
  920.       }
  921.    else
  922.       {
  923.       pNextFree = DiskStringCopy (&pDiskLine->dsSystemName, 
  924.                                   pLine->lnSystemName,
  925.                                   pNextFree) ;
  926.       }
  927.  
  928.    pNextFree = DiskStringCopy (&pDiskLine->dsObjectName, 
  929.                                pLine->lnObjectName,
  930.                                pNextFree) ;
  931.  
  932.    pNextFree = DiskStringCopy (&pDiskLine->dsCounterName, 
  933.                                pLine->lnCounterName,
  934.                                pNextFree) ;
  935.  
  936.    pNextFree = DiskStringCopy (&pDiskLine->dsParentObjName, 
  937.                                pLine->lnParentObjName,
  938.                                pNextFree) ;
  939.  
  940.    pNextFree = DiskStringCopy (&pDiskLine->dsInstanceName, 
  941.                                pLine->lnInstanceName,
  942.                                pNextFree) ;
  943.  
  944.    pNextFree = DiskStringCopy (&pDiskLine->dsPINName, 
  945.                                pLine->lnPINName,
  946.                                pNextFree) ;
  947.  
  948.    pNextFree = DiskStringCopy (&pDiskLine->dsAlertProgram, 
  949.                                pLine->lpszAlertProgram,
  950.                                pNextFree) ;
  951.  
  952.  
  953.  
  954.    FileWrite (hFile, pDiskLine, dwLength) ;
  955.    MemoryFree (pDiskLine) ;
  956.    return (TRUE) ;
  957.  
  958. //ErrorBadLine:
  959.    MemoryFree (pDiskLine) ;
  960.    return (FALSE) ;
  961.    }  // WriteLine
  962.  
  963.  
  964. // we are not doing printing.  In case we need this
  965. // later, then define DO_PRINTING
  966. #ifdef DO_PRINTING
  967. int aiPrinterLineStyles [] = 
  968.    {
  969.    PS_SOLID,
  970.    PS_DASH,
  971.    PS_DOT,
  972.    PS_DASHDOT,
  973.    PS_DASHDOTDOT
  974.    } ;
  975. #define NumPrinterLineStyles()   \
  976.    (sizeof (aiPrinterLineStyles) / sizeof (aiPrinterLineStyles [0]))
  977.  
  978.  
  979. COLORREF acrPrinterLineColors [] =
  980.    {
  981.    RGB (192, 192, 192),
  982.    RGB (128, 128, 128), 
  983.    RGB (64, 64, 64),
  984.    RGB (0, 0, 0)
  985.    }  ;
  986.  
  987.  
  988. #define NumPrinterLineColors()   \
  989.    (sizeof (acrPrinterLineColors) / sizeof (acrPrinterLineColors [0]))
  990. #endif      // DO_PRINTING
  991.  
  992.  
  993. HPEN LineCreatePen (HDC hDC,
  994.                     PLINEVISUAL pVisual,
  995.                     BOOL bForPrint)
  996.    {  // LineCreatePen
  997.    HPEN        hPen ;
  998. #ifdef DO_PRINTING
  999.    LOGBRUSH    logBrush ;
  1000.  
  1001.  
  1002.    if (bForPrint)
  1003.       {
  1004.       logBrush.lbStyle = PS_SOLID ;
  1005. //!!         aiPrinterLineStyles [pVisual->iColorIndex % NumPrinterLineStyles ()] ;
  1006.       logBrush.lbColor = 
  1007.          acrPrinterLineColors [pVisual->iColorIndex % NumPrinterLineColors ()] ;
  1008.       logBrush.lbHatch = 0 ;
  1009.  
  1010.       hPen = ExtCreatePen (logBrush.lbStyle | 
  1011.                            PS_GEOMETRIC | 
  1012.                            PS_ENDCAP_SQUARE | 
  1013.                            PS_JOIN_BEVEL,
  1014.                            VertInchPixels (hDC, pVisual->iWidth, 20),
  1015.                            &logBrush,
  1016.                            0, NULL) ;
  1017.       }
  1018.    else
  1019. #endif
  1020.       hPen = CreatePen (pVisual->iStyle,
  1021.                         pVisual->iWidth, 
  1022.                         pVisual->crColor) ;
  1023.  
  1024.    return (hPen) ;
  1025.    }  // LineCreatePen
  1026.  
  1027.  
  1028.  
  1029. VOID FreeLines (PLINESTRUCT pLineFirst)
  1030.    {  // FreeLines
  1031.    PLINESTRUCT    pLine,next_line;
  1032.  
  1033.  
  1034.    for (pLine = pLineFirst; pLine; pLine = next_line)
  1035.       {
  1036.       next_line = pLine->pLineNext;
  1037.       LineFree (pLine) ;
  1038.       }
  1039.    }  // FreeLines
  1040.  
  1041. 
  1042.